import QtQuick
import Qt5Compat.GraphicalEffects
import "../components"
import music_player

Rectangle {
    id: titleBar
    width: parent.width
    height: 50
    color: p_theme.currentTheme().background
    MouseArea {
        anchors.fill: parent
        property var click_pos: Qt.point(0, 0)
        onPositionChanged: function (mouse) {
            if (!pressed || window.mouse_pos !== FramelessWindow.NORMAL)
                return;
            if (!window.startSystemMove()) {
                let offset = Qt.point(mouseX - click_pos.x, mouseY - click_pos.y);
                window.x += offset.x;
                window.y += offset.y;
            }
        }
        onPressedChanged: function (mouse) {
            click_pos = Qt.point(mouseX, mouseY);
        }
        onPressed: {
            if (window.resizeing)
                return;
            cursorShape = Qt.SizeAllCursor;
        }

        onReleased: {
            if (window.resizeing)
                return;
            cursorShape = Qt.ArrowCursor;
        }

        onDoubleClicked: function () {
            if (window.visibility == Window.Maximized || window.visibility == Window.FullScreen) {
                window.showNormal();
            } else {
                // window.showFullScreen();
                window.showMaximized();
            }
        }
        Row {
            anchors.left: parent.left
            height: parent.height
            spacing: 10
            Item {
                width: 10
                height: parent.height
            }

            Image {
                id: logo
                anchors.verticalCenter: parent.verticalCenter
                width: 30
                height: width
                source: "qrc:/icon/logo.png"
                smooth: true
                fillMode: Image.PreserveAspectCrop
            }
            Text {
                id: title
                anchors.verticalCenter: parent.verticalCenter
                text: qsTr("音乐播放器")
                font.pixelSize: 20
                color: p_theme.currentTheme().fontColor
            }
        }
    }
    Row {
        anchors.right: parent.right
        width: 130
        height: parent.height
        spacing: 13
        ToolTipButton {
            anchors.verticalCenter: parent.verticalCenter
            size: 30
            iconScale: 0.7
            iconSource: "qrc:/icon/to-min.svg"
            onClick: window.showMinimized()
        }
        ToolTipButton {
            anchors.verticalCenter: parent.verticalCenter
            size: 30
            iconScale: 0.5
            iconSource: window.visibility == Window.Maximized ? "qrc:/icon/to-normal.svg" : "qrc:/icon/to-max.svg"
            onClick: function () {
                if (window.visibility == Window.Maximized || window.Windowed == Window.FullScreen) {
                    window.showNormal();
                } else {
                    window.showMaximized();
                }
            }
        }
        ToolTipButton {
            anchors.verticalCenter: parent.verticalCenter
            size: 30
            iconScale: 0.5
            iconSource: "qrc:/icon/quit.svg"
            onClick: Qt.quit()
        }
    }
}
